package com.macro.mall.commission.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.macro.mall.commission.entity.UserAccountEntity;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

/**
 * 用户佣金账户 mapper
 *
 * @author xuyanjun
 * @date 2019-12-11
 */
public interface UserAccountMapper extends BaseMapper<UserAccountEntity> {

    /**
     * 增加余额
     *
     * @param id     id
     * @param amount 金额
     * @return 受影响的行数
     */
    @Update("update commission_user_account set balance=balance+#{amount},total=total+#{amount} where id=#{id}; ")
    int addBalance(@Param("id") long id, @Param("amount") int amount);

    /**
     * 减少余额
     *
     * @param id     id
     * @param amount 金额
     * @return 受影响的行数
     */
    @Update("update commission_user_account set balance=balance-#{amount} where id=#{id}; ")
    int reduceBalance(@Param("id") long id, @Param("amount") int amount);
}

